home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.sprintlink.net!eskimo!scs
- From: scs@eskimo.com (Steve Summit)
- Subject: Re: What is &Variable (declared as: char Variable[10])?
- X-Nntp-Posting-Host: eskimo.com
- Message-ID: <DnLx2r.323@eskimo.com>
- Sender: news@eskimo.com (News User Id)
- Organization: schmorganization
- References: <4gqpa1$3h9@alcor.usc.edu> <4gsdno$1bg@umbc9.umbc.edu> <4gvlnlINNppj@anvil.ugrad.cs.ubc.ca>
- Date: Fri, 1 Mar 1996 21:01:38 GMT
-
- In article <4gvlnlINNppj@anvil.ugrad.cs.ubc.ca>, c2a192@ugrad.cs.ubc.ca
- (Kazimir Kylheku) writes:
- > In article <4gsdno$1bg@umbc9.umbc.edu>,
- > Jonas J. Schlein <schlein@umbc.edu> wrote:
- >> I'm having trouble understanding why it matters? You almost never use the
- >> address of an array directly unless doing something tricky with pointers
- >> or with particular dimensions of a multiple dimensional array.
- >
- > Not necessarily. The address of an array is very useful in
- > abstracting away the representation of a variable that happens
- > to be represented as an array... The client can declare a
- > variable of [abstract] type... without caring whether it is a
- > struct, double, long, array or union.
-
- What you say about abstract types is, in general, true, but it's
- probably not a good idea to instantiate an abstract type with an
- underlying array type, because arrays are second-class citizens
- in C.
-
- A client programmer might reasonably assume that the sequence
-
- abstract_t x;
- f(x);
-
- could not modify x. In C, this assumption is of course not valid
- if abstract_t happens to have array type.
-
- As it happens, standard C does contain one abstract type which
- is, underneath, an array: jmp_buf, from <setjmp.h>. Because
- setjmp() is traditionally called as
-
- jmp_buf env;
- setjmp(env);
-
- and because setjmp() is in fact specified as accepting a
- parameter of type jmp_buf, but since setjmp must modify its
- argument, we are left with the peculiar requirement that jmp_buf,
- though seemingly abstract, must be an array type.
-
- If, one day, you find yourself wanting to implement an abstract
- type with an array, it's a good idea to wrap the array in a
- structure, so that it will be a first-class type. Otherwise, you
- may run into surprises (when your callers find their variables
- being unexpectedly modified by calls to your routines) or you may
- accidentally lock yourself into maintaining the allegedly
- abstract type as an array type (as happened with jmp_buf).
-
- Steve Summit
- scs@eskimo.com
-